﻿/**
 * 选选择情况发生变化时，自动启用和禁用子组件，这些子组件必须配置：autoEnableAndDisable = true|false。
 */
Ext.define('Happy.table.plugin.AutoEnableAndDisableChildren', {
    extend: 'Ext.AbstractPlugin',
    alias: 'plugin.auto-enable-and-disable-children',

    /**
     * 重写 ExtJs。
     */
    init: function (table) {
        var me = this;

        me.table = table;
        table.on('selectionchange', me.onSelectionChangeHandler, me);
    },

    /**
     * 选选择情况发生变化时的处理方法。
     * 
     * @private
     */
    onSelectionChangeHandler: function (sender, selected) {
        var me = this;

        var hasRowSelected = selected.length > 0;

        var compontents = me.table.query('component[autoEnableAndDisable=true]');

        Ext.Array.each(compontents, function (compontent) {
            compontent.setDisabled(!hasRowSelected);
        });
    }
});